﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;

namespace TeBigScreenWpf.Common
{
    public struct HLSColor
    {
        public HLSColor(Color color)
        {
            int r = (int)color.R;
            int g = (int)color.G;
            int b = (int)color.B;
            int num = Math.Max(Math.Max(r, g), b);
            int num2 = Math.Min(Math.Min(r, g), b);
            int num3 = num + num2;
            this.Luminosity = (num3 * 240 + 255) / 510;
            int num4 = num - num2;
            if (num4 == 0)
            {
                this.Saturation = 0;
                this.Hue = 160;
                return;
            }
            if (this.Luminosity <= 120)
            {
                this.Saturation = (num4 * 240 + num3 / 2) / num3;
            }
            else
            {
                this.Saturation = (num4 * 240 + (510 - num3) / 2) / (510 - num3);
            }
            int num5 = ((num - r) * 40 + num4 / 2) / num4;
            int num6 = ((num - g) * 40 + num4 / 2) / num4;
            int num7 = ((num - b) * 40 + num4 / 2) / num4;
            if (r == num)
            {
                this.Hue = num7 - num6;
            }
            else if (g == num)
            {
                this.Hue = 80 + num5 - num7;
            }
            else
            {
                this.Hue = 160 + num6 - num5;
            }
            if (this.Hue < 0)
            {
                this.Hue += 240;
            }
            if (this.Hue > 240)
            {
                this.Hue -= 240;
            }
        }

        public int Luminosity { get; }
        public int Hue { get; set; }
        public int Saturation { get; set; }

        public Color Lighter(float percLighter)
        {
            int num = this.Luminosity;
            int num2 = this.NewLuma(500, true);
            return this.ColorFromHLS(this.Hue, num + (int)((float)(num2 - num) * percLighter), this.Saturation);
        }

        public Color Darker(float percDarker)
        {
            int num = 0;
            int num2 = this.NewLuma(-333, true);
            return this.ColorFromHLS(this.Hue, num2 - (int)((float)(num2 - num) * percDarker), this.Saturation);
        }

        public override bool Equals(object o)
        {
            if (!(o is HLSColor))
            {
                return false;
            }
            HLSColor hlscolor = (HLSColor)o;
            return this.Hue == hlscolor.Hue && this.Saturation == hlscolor.Saturation && this.Luminosity == hlscolor.Luminosity;
        }

        public static bool operator ==(HLSColor a, HLSColor b)
        {
            return a.Equals(b);
        }

        public static bool operator !=(HLSColor a, HLSColor b)
        {
            return !a.Equals(b);
        }

        public override int GetHashCode()
        {
            return this.Hue << 6 | this.Saturation << 2 | this.Luminosity;
        }

        private int NewLuma(int n, bool scale)
        {
            return this.NewLuma(this.Luminosity, n, scale);
        }

        private int NewLuma(int luminosity, int n, bool scale)
        {
            if (n == 0)
            {
                return luminosity;
            }
            if (!scale)
            {
                int num = luminosity + (int)((long)n * 240L / 1000L);
                if (num < 0)
                {
                    num = 0;
                }
                if (num > 240)
                {
                    num = 240;
                }
                return num;
            }
            if (n > 0)
            {
                return (int)(((long)(luminosity * (1000 - n)) + 241L * (long)n) / 1000L);
            }
            return luminosity * (n + 1000) / 1000;
        }

        public Color ToColor()
        {
            return ColorFromHLS(this.Hue, this.Luminosity, this.Saturation);
        }

        public Color ToColor(int luminosity, int saturation)
        {
            return ColorFromHLS(this.Hue, luminosity, saturation);
        }

        private Color ColorFromHLS(int hue, int luminosity, int saturation)
        {
            byte blue;
            byte red;
            byte green;
            if (saturation == 0)
            {
                green = (red = (blue = (byte)(luminosity * 255 / 240)));
                if (hue != 160)
                {
                }
            }
            else
            {
                int num;
                if (luminosity <= 120)
                {
                    num = (luminosity * (240 + saturation) + 120) / 240;
                }
                else
                {
                    num = luminosity + saturation - (luminosity * saturation + 120) / 240;
                }
                int n = 2 * luminosity - num;
                red = (byte)((this.HueToRGB(n, num, hue + 80) * 255 + 120) / 240);
                green = (byte)((this.HueToRGB(n, num, hue) * 255 + 120) / 240);
                blue = (byte)((this.HueToRGB(n, num, hue - 80) * 255 + 120) / 240);
            }
            return Color.FromArgb(0xff, red, green, blue);
        }

        private int HueToRGB(int n1, int n2, int hue)
        {
            if (hue < 0)
            {
                hue += 240;
            }
            if (hue > 240)
            {
                hue -= 240;
            }
            if (hue < 40)
            {
                return n1 + ((n2 - n1) * hue + 20) / 40;
            }
            if (hue < 120)
            {
                return n2;
            }
            if (hue < 160)
            {
                return n1 + ((n2 - n1) * (160 - hue) + 20) / 40;
            }
            return n1;
        }

        private const int ShadowAdj = -333;

        private const int HilightAdj = 500;

        private const int WatermarkAdj = -50;

        private const int Range = 240;

        private const int HLSMax = 240;

        private const int RGBMax = 255;

        private const int Undefined = 160;
    }

    public static class ColorHelper
    {
        static ColorHelper()
        {
            Array.Sort<ColorHelper.ColorDescription>(ColorHelper.defaultColors, new Comparison<ColorHelper.ColorDescription>(ColorHelper.ColorDescription.Compare));
        }

        private static int FindColorDescriptionIndexByName(string name)
        {
            int num = 0;
            int num2 = ColorHelper.defaultColors.GetLength(0) - 1;
            int num3 = ColorHelper.defaultColors[0].Name.CompareTo(name);
            if (num3 > 0)
            {
                return -1;
            }
            if (num3 == 0)
            {
                return 0;
            }
            num3 = ColorHelper.defaultColors[num2].Name.CompareTo(name);
            if (num3 < 0)
            {
                return -1;
            }
            if (num3 == 0)
            {
                return 0;
            }
            int num4;
            for (; ; )
            {
                if ((num2 - num) % 2 != 0)
                {
                    num4 = (num2 + num - 1) / 2;
                }
                else
                {
                    num4 = (num2 + num) / 2;
                }
                num3 = ColorHelper.defaultColors[num4].Name.CompareTo(name);
                if (num3 == 0)
                {
                    break;
                }
                if (num3 > 0)
                {
                    if (num2 == num4)
                    {
                        return -1;
                    }
                    num2 = num4;
                }
                else
                {
                    if (num == num4)
                    {
                        return -1;
                    }
                    num = num4;
                }
                if (num == num2 && num == num4)
                {
                    return -1;
                }
            }
            return num4;
        }

        public static System.Windows.Media.Color CreateColorFromString(string stringValue)
        {
            System.Windows.Media.Color? color = ColorHelper.CreateColorFromStringCore(stringValue);
            if (color != null)
            {
                return color.Value;
            }
            return default(System.Windows.Media.Color);
        }

        private static System.Windows.Media.Color? CreateColorFromStringCore(string stringValue)
        {
            int num = ColorHelper.FindColorDescriptionIndexByName(stringValue);
            string text = (num != -1) ? ColorHelper.defaultColors[num].Value : stringValue;
            if (!text.StartsWith("#"))
            {
                return null;
            }
            if (text.Length != 7 && text.Length != 9)
            {
                return null;
            }
            int num2;
            if (!int.TryParse(text.Substring(1), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out num2))
            {
                return null;
            }
            System.Windows.Media.Color transparent = Colors.Transparent;
            transparent.B = (byte)(num2 & 255);
            transparent.G = (byte)(num2 >> 8 & 255);
            transparent.R = (byte)(num2 >> 16 & 255);
            transparent.A = ((text.Length == 7) ? (transparent.A = byte.MaxValue) : (transparent.A = (byte)(num2 >> 24 & 255)));
            return new System.Windows.Media.Color?(transparent);
        }

        public static bool IsValidColorStringValue(string stringValue)
        {
            return ColorHelper.CreateColorFromStringCore(stringValue) != null;
        }

        private static byte OverlayComponents(byte component1, byte component2)
        {
            if (component1 < 128)
            {
                return ColorHelper.MultiplyComponents((int)component1, (int)component2);
            }
            if (component1 > 128)
            {
                return ColorHelper.ScreenComponents((int)component1, (int)component2);
            }
            return component2;
        }

        private static byte ScreenComponents(int component1, int component2)
        {
            int num = 255 - 2 * (255 - component1) * (255 - component2) / 255;
            if (num >= 0)
            {
                return (byte)num;
            }
            return 0;
        }

        private static byte MultiplyComponents(int component1, int component2)
        {
            int num = 2 * component1 * component2 / 255;
            if (num <= 255)
            {
                return (byte)num;
            }
            return byte.MaxValue;
        }

        public static System.Windows.Media.Color OverlayColor(System.Windows.Media.Color color1, System.Windows.Media.Color color2)
        {
            return System.Windows.Media.Color.FromArgb(ColorHelper.MixAlpha(color1.A, color2.A), ColorHelper.OverlayComponents(color1.R, color2.R), ColorHelper.OverlayComponents(color1.G, color2.G), ColorHelper.OverlayComponents(color1.B, color2.B));
        }

        private static void NormalizeGradientBrush(GradientBrush gradientBrush)
        {
            for (int i = 0; i < gradientBrush.GradientStops.Count - 1; i++)
            {
                int num = (int)Math.Max(gradientBrush.GradientStops[i].Color.R, gradientBrush.GradientStops[i + 1].Color.R);
                int num2 = (int)Math.Min(gradientBrush.GradientStops[i].Color.R, gradientBrush.GradientStops[i + 1].Color.R);
                if (num2 < 128 && num > 128)
                {
                    int num3 = (int)(gradientBrush.GradientStops[i].Color.R - gradientBrush.GradientStops[i + 1].Color.R);
                    double num4 = gradientBrush.GradientStops[i + 1].Offset - gradientBrush.GradientStops[i].Offset;
                    double num5 = (double)(gradientBrush.GradientStops[i].Color.R - ColorHelper.DefaultColor.R) / (double)num3 * num4 + gradientBrush.GradientStops[i].Offset;
                    int num6 = (int)(gradientBrush.GradientStops[i].Color.A - gradientBrush.GradientStops[i + 1].Color.A);
                    System.Windows.Media.Color defaultColor = ColorHelper.DefaultColor;
                    defaultColor.A = (byte)((int)((gradientBrush.GradientStops[i].Offset - num5) / num4 * (double)num6) + (int)gradientBrush.GradientStops[i + 1].Color.A);
                    gradientBrush.GradientStops.Insert(i + 1, new GradientStop
                    {
                        Color = defaultColor,
                        Offset = num5
                    });
                }
            }
        }

        public static byte MixAlpha(byte a1, byte a2)
        {
            return System.Convert.ToByte((double)a1 / 255.0 * ((double)a2 / 255.0) * 255.0);
        }

        public static System.Windows.Media.Brush MixColors(System.Windows.Media.Brush brush, System.Windows.Media.Color targetColor)
        {
            if (brush == null)
            {
                return null;
            }
            System.Windows.Media.Brush brush2 = brush.CloneCurrentValue();
            SolidColorBrush solidColorBrush = brush2 as SolidColorBrush;
            if (solidColorBrush == null)
            {
                GradientBrush gradientBrush = brush2 as GradientBrush;
                if (gradientBrush == null)
                {
                    return brush2;
                }
                using (GradientStopCollection.Enumerator enumerator = gradientBrush.GradientStops.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        GradientStop gradientStop = enumerator.Current;
                        gradientStop.Color = ColorHelper.OverlayColor(gradientStop.Color, targetColor);
                    }
                    return brush2;
                }
            }
            solidColorBrush.Color = ColorHelper.OverlayColor(solidColorBrush.Color, targetColor);
            return brush2;
        }

        public static System.Windows.Media.Brush NormalizeGradients(System.Windows.Media.Brush brush)
        {
            System.Windows.Media.Brush brush2 = brush.CloneCurrentValue();
            GradientBrush gradientBrush = brush2 as GradientBrush;
            if (gradientBrush != null)
            {
                ColorHelper.NormalizeGradientBrush(gradientBrush);
                return gradientBrush;
            }
            return brush2;
        }

        public static System.Windows.Media.Color Brightness(System.Windows.Media.Color c, double brightness)
        {
            if (brightness.IsZero())
            {
                return c;
            }
            if (brightness >= 0.0)
            {
                return ColorHelper.Light(c, brightness);
            }
            return ColorHelper.Dark(c, -brightness);
        }

        private static System.Windows.Media.Color Light(System.Windows.Media.Color color, double factor)
        {
            double num = 0.001;
            double num2 = 1.999;
            factor = Math.Min(Math.Max(factor, 0.0), 1.0);
            float percOfLightLight = (float)(num + factor * (num2 - num));

            return new HLSColor(color).Lighter(percOfLightLight);
        }

        private static System.Windows.Media.Color Dark(System.Windows.Media.Color color, double factor)
        {
            double num = -0.5;
            double num2 = 1.0;
            factor = Math.Min(Math.Max(factor, num), num2);
            float percOfDarkDark = (float)(num + factor * (num2 - num));

            return new HLSColor(color).Darker(percOfDarkDark);
        }

        public static bool IsTransparent(System.Windows.Media.Color c)
        {
            return c.A == 0;
        }

        public static float GetHue(System.Windows.Media.Color c)
        {
            return System.Drawing.Color.FromArgb((int)c.A, (int)c.R, (int)c.G, (int)c.B).GetHue();
        }

        public static float GetBrightness(System.Windows.Media.Color c)
        {
            return System.Drawing.Color.FromArgb((int)c.A, (int)c.R, (int)c.G, (int)c.B).GetBrightness();
        }

        public static float GetSaturation(System.Windows.Media.Color c)
        {
            return System.Drawing.Color.FromArgb((int)c.A, (int)c.R, (int)c.G, (int)c.B).GetSaturation();
        }

        public static System.Windows.Media.Color FromHSB(double h, double s, double b)
        {
            double num = h / 60.0;
            int num2 = (int)Math.Floor(num) % 6;
            double num3 = num - Math.Floor(num);
            double num4 = b * (1.0 - s);
            double num5 = b * (1.0 - num3 * s);
            double num6 = b * (1.0 - (1.0 - num3) * s);
            switch (num2)
            {
                case 0:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(b * 255.0), (byte)(num6 * 255.0), (byte)(num4 * 255.0));

                case 1:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(num5 * 255.0), (byte)(b * 255.0), (byte)(num4 * 255.0));

                case 2:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(num4 * 255.0), (byte)(b * 255.0), (byte)(num6 * 255.0));

                case 3:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(num4 * 255.0), (byte)(num5 * 255.0), (byte)(b * 255.0));

                case 4:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(num6 * 255.0), (byte)(num6 * 255.0), (byte)(b * 255.0));

                case 5:
                    return System.Windows.Media.Color.FromArgb(byte.MaxValue, (byte)(b * 255.0), (byte)(num4 * 255.0), (byte)(num5 * 255.0));

                default:
                    return Colors.White;
            }
        }

        public static System.Windows.Media.Brush MixColors2(System.Windows.Media.Brush brush, System.Windows.Media.Color targetColor)
        {
            if (brush == null)
            {
                return null;
            }
            System.Windows.Media.Brush brush2 = brush.CloneCurrentValue();
            SolidColorBrush solidColorBrush = brush2 as SolidColorBrush;
            if (solidColorBrush != null)
            {
                solidColorBrush.Color = ColorHelper.MixColors2(solidColorBrush.Color, targetColor);
                solidColorBrush.Freeze();
                return solidColorBrush;
            }
            GradientBrush gradientBrush = brush2 as GradientBrush;
            if (gradientBrush != null)
            {
                foreach (GradientStop gradientStop in gradientBrush.GradientStops)
                {
                    gradientStop.Color = ColorHelper.MixColors2(gradientStop.Color, targetColor);
                }
                gradientBrush.Freeze();
                return gradientBrush;
            }
            return brush2;
        }

        private static System.Windows.Media.Color MixColors2(System.Windows.Media.Color baseColor, System.Windows.Media.Color targetColor)
        {
            double num = (double)Math.Min(1f, ColorHelper.GetBrightness(baseColor));
            double num2 = (double)ColorHelper.GetHue(targetColor);
            if (num2 > 0.0)
            {
                double s = (double)(ColorHelper.GetSaturation(baseColor) * 0.45f);
                System.Windows.Media.Color color = ColorHelper.FromHSB(num2, s, num);
                return System.Windows.Media.Color.FromArgb(targetColor.A, color.R, color.G, color.B);
            }
            byte b = (byte)(num * 255.0);
            return ColorHelper.OverlayColor(System.Windows.Media.Color.FromArgb(baseColor.A, b, b, b), targetColor);
        }

        private static ColorHelper.ColorDescription[] defaultColors = new ColorHelper.ColorDescription[]
        {
            new ColorHelper.ColorDescription("Transparent", "#00FFFFFF"),
            new ColorHelper.ColorDescription("Snow", "#FFFFFAFA"),
            new ColorHelper.ColorDescription("GhostWhite", "#FFF8F8FF"),
            new ColorHelper.ColorDescription("WhiteSmoke", "#FFF5F5F5"),
            new ColorHelper.ColorDescription("Gainsboro", "#FFDCDCDC"),
            new ColorHelper.ColorDescription("FloralWhite", "#FFFFFAF0"),
            new ColorHelper.ColorDescription("OldLace", "#FFFDF5E6"),
            new ColorHelper.ColorDescription("Linen", "#FFFAF0E6"),
            new ColorHelper.ColorDescription("AntiqueWhite", "#FFFAEBD7"),
            new ColorHelper.ColorDescription("PapayaWhip", "#FFFFEFD5"),
            new ColorHelper.ColorDescription("BlanchedAlmond", "#FFFFEBCD"),
            new ColorHelper.ColorDescription("Bisque", "#FFFFE4C4"),
            new ColorHelper.ColorDescription("PeachPuff", "#FFFFDAB9"),
            new ColorHelper.ColorDescription("NavajoWhite", "#FFFFDEAD"),
            new ColorHelper.ColorDescription("Moccasin", "#FFFFE4B5"),
            new ColorHelper.ColorDescription("Cornsilk", "#FFFFF8DC"),
            new ColorHelper.ColorDescription("Ivory", "#FFFFFFF0"),
            new ColorHelper.ColorDescription("LemonChiffon", "#FFFFFACD"),
            new ColorHelper.ColorDescription("Seashell", "#FFFFF5EE"),
            new ColorHelper.ColorDescription("Honeydew", "#FFF0FFF0"),
            new ColorHelper.ColorDescription("MintCream", "#FFF5FFFA"),
            new ColorHelper.ColorDescription("DeepBlue", "#FFF0FFFF"),
            new ColorHelper.ColorDescription("AliceBlue", "#FFF0F8FF"),
            new ColorHelper.ColorDescription("Lavender", "#FFE6E6FA"),
            new ColorHelper.ColorDescription("LavenderBlush", "#FFFFF0F5"),
            new ColorHelper.ColorDescription("MistyRose", "#FFFFE4E1"),
            new ColorHelper.ColorDescription("White", "#FFFFFFFF"),
            new ColorHelper.ColorDescription("Black", "#FF000000"),
            new ColorHelper.ColorDescription("DarkSlateGray", "#FF2F4F4F"),
            new ColorHelper.ColorDescription("DimGray", "#FF696969"),
            new ColorHelper.ColorDescription("SlateGray", "#FF708090"),
            new ColorHelper.ColorDescription("LightSlateGray", "#FF778899"),
            new ColorHelper.ColorDescription("DarkGray", "#FFA9A9A9"),
            new ColorHelper.ColorDescription("Gray", "#FF808080"),
            new ColorHelper.ColorDescription("Silver", "#FFC0C0C0"),
            new ColorHelper.ColorDescription("LightGray", "#FFD3D3D3"),
            new ColorHelper.ColorDescription("DarkSlateBlue", "#FF483D8B"),
            new ColorHelper.ColorDescription("SlateBlue", "#FF6A5ACD"),
            new ColorHelper.ColorDescription("MediumSlateBlue", "#FF7B68EE"),
            new ColorHelper.ColorDescription("MidnightBlue", "#FF191970"),
            new ColorHelper.ColorDescription("Navy", "#FF000080"),
            new ColorHelper.ColorDescription("DarkBlue", "#FF00008B"),
            new ColorHelper.ColorDescription("MediumBlue", "#FF0000CD"),
            new ColorHelper.ColorDescription("Blue", "#FF0000FF"),
            new ColorHelper.ColorDescription("RoyalBlue", "#FF4169E1"),
            new ColorHelper.ColorDescription("CornflowerBlue", "#FF6495ED"),
            new ColorHelper.ColorDescription("DodgerBlue", "#FF1E90FF"),
            new ColorHelper.ColorDescription("DeepSkyBlue", "#FF00BFFF"),
            new ColorHelper.ColorDescription("SkyBlue", "#FF87CEEB"),
            new ColorHelper.ColorDescription("LightSkyBlue", "#FF87CEFA"),
            new ColorHelper.ColorDescription("SteelBlue", "#FF4682B4"),
            new ColorHelper.ColorDescription("LightSteelBlue", "#FFB0C4DE"),
            new ColorHelper.ColorDescription("LightBlue", "#FFADD8E6"),
            new ColorHelper.ColorDescription("PowderBlue", "#FFB0E0E6"),
            new ColorHelper.ColorDescription("PaleTurquoise", "#FFAFEEEE"),
            new ColorHelper.ColorDescription("DarkTurquoise", "#FF00CED1"),
            new ColorHelper.ColorDescription("MediumTurquoise", "#FF48D1CC"),
            new ColorHelper.ColorDescription("Turquoise", "#FF40E0D0"),
            new ColorHelper.ColorDescription("Aqua", "#FF00FFFF"),
            new ColorHelper.ColorDescription("DarkCyan", "#FF008B8B"),
            new ColorHelper.ColorDescription("Cyan", "#FF00FFFF"),
            new ColorHelper.ColorDescription("LightCyan", "#FFE0FFFF"),
            new ColorHelper.ColorDescription("CadetBlue", "#FF5F9EA0"),
            new ColorHelper.ColorDescription("MediumAquamarine", "#FF66CDAA"),
            new ColorHelper.ColorDescription("Aquamarine", "#FF7FFFD4"),
            new ColorHelper.ColorDescription("DarkGreen", "#FF006400"),
            new ColorHelper.ColorDescription("DarkOliveGreen", "#FF556B2F"),
            new ColorHelper.ColorDescription("DarkSeaGreen", "#FF8FBC8F"),
            new ColorHelper.ColorDescription("Teal", "#FF008080"),
            new ColorHelper.ColorDescription("SeaGreen", "#FF2E8B57"),
            new ColorHelper.ColorDescription("MediumSeaGreen", "#FF3CB371"),
            new ColorHelper.ColorDescription("LightSeaGreen", "#FF20B2AA"),
            new ColorHelper.ColorDescription("PaleGreen", "#FF98FB98"),
            new ColorHelper.ColorDescription("LightGreen", "#FF90EE90"),
            new ColorHelper.ColorDescription("SpringGreen", "#FF00FF7F"),
            new ColorHelper.ColorDescription("LawnGreen", "#FF7CFC00"),
            new ColorHelper.ColorDescription("Green", "#FF008000"),
            new ColorHelper.ColorDescription("Chartreuse", "#FF7FFF00"),
            new ColorHelper.ColorDescription("MediumSpringGreen", "#FF00FA9A"),
            new ColorHelper.ColorDescription("GreenYellow", "#FFADFF2F"),
            new ColorHelper.ColorDescription("Lime", "#FF00FF00"),
            new ColorHelper.ColorDescription("LimeGreen", "#FF32CD32"),
            new ColorHelper.ColorDescription("YellowGreen", "#FF9ACD32"),
            new ColorHelper.ColorDescription("ForestGreen", "#FF228B22"),
            new ColorHelper.ColorDescription("Olive", "#FF808000"),
            new ColorHelper.ColorDescription("OliveDrab", "#FF6B8E23"),
            new ColorHelper.ColorDescription("DarkKhaki", "#FFBDB76B"),
            new ColorHelper.ColorDescription("Khaki", "#FFF0E68C"),
            new ColorHelper.ColorDescription("PaleGoldenrod", "#FFEEE8AA"),
            new ColorHelper.ColorDescription("LightGoldenrodYellow", "#FFFAFAD2"),
            new ColorHelper.ColorDescription("LightYellow", "#FFFFFFE0"),
            new ColorHelper.ColorDescription("Yellow", "#FFFFFF00"),
            new ColorHelper.ColorDescription("Gold", "#FFFFD700"),
            new ColorHelper.ColorDescription("Goldenrod", "#FFDAA520"),
            new ColorHelper.ColorDescription("DarkGoldenrod", "#FFB8860B"),
            new ColorHelper.ColorDescription("RosyBrown", "#FFBC8F8F"),
            new ColorHelper.ColorDescription("IndianRed", "#FFCD5C5C"),
            new ColorHelper.ColorDescription("SaddleBrown", "#FF8B4513"),
            new ColorHelper.ColorDescription("Sienna", "#FFA0522D"),
            new ColorHelper.ColorDescription("Peru", "#FFCD853F"),
            new ColorHelper.ColorDescription("Burlywood", "#FFDEB887"),
            new ColorHelper.ColorDescription("Beige", "#FFF5F5DC"),
            new ColorHelper.ColorDescription("Wheat", "#FFF5DEB3"),
            new ColorHelper.ColorDescription("SandyBrown", "#FFF4A460"),
            new ColorHelper.ColorDescription("Tan", "#FFD2B48C"),
            new ColorHelper.ColorDescription("Chocolate", "#FFD2691E"),
            new ColorHelper.ColorDescription("Firebrick", "#FFB22222"),
            new ColorHelper.ColorDescription("Brown", "#FFA52A2A"),
            new ColorHelper.ColorDescription("DarkSalmon", "#FFE9967A"),
            new ColorHelper.ColorDescription("Salmon", "#FFFA8072"),
            new ColorHelper.ColorDescription("LightSalmon", "#FFFFA07A"),
            new ColorHelper.ColorDescription("Orange", "#FFFFA500"),
            new ColorHelper.ColorDescription("DarkOrange", "#FFFF8C00"),
            new ColorHelper.ColorDescription("Coral", "#FFFF7F50"),
            new ColorHelper.ColorDescription("LightCoral", "#FFF08080"),
            new ColorHelper.ColorDescription("Tomato", "#FFFF6347"),
            new ColorHelper.ColorDescription("OrangeRed", "#FFFF4500"),
            new ColorHelper.ColorDescription("Red", "#FFFF0000"),
            new ColorHelper.ColorDescription("HotPink", "#FFFF69B4"),
            new ColorHelper.ColorDescription("DeepPink", "#FFFF1493"),
            new ColorHelper.ColorDescription("Pink", "#FFFFC0CB"),
            new ColorHelper.ColorDescription("LightPink", "#FFFFB6C1"),
            new ColorHelper.ColorDescription("PaleVioletRed", "#FFDB7093"),
            new ColorHelper.ColorDescription("Maroon", "#FF800000"),
            new ColorHelper.ColorDescription("MediumVioletRed", "#FFC71585"),
            new ColorHelper.ColorDescription("Magenta", "#FFFF00FF"),
            new ColorHelper.ColorDescription("Fuchsia", "#FFFF00FF"),
            new ColorHelper.ColorDescription("Violet", "#FFEE82EE"),
            new ColorHelper.ColorDescription("Plum", "#FFDDA0DD"),
            new ColorHelper.ColorDescription("Orchid", "#FFDA70D6"),
            new ColorHelper.ColorDescription("MediumOrchid", "#FFBA55D3"),
            new ColorHelper.ColorDescription("DarkOrchid", "#FF9932CC"),
            new ColorHelper.ColorDescription("DarkViolet", "#FF9400D3"),
            new ColorHelper.ColorDescription("BlueViolet", "#FF8A2BE2"),
            new ColorHelper.ColorDescription("Purple", "#FF800080"),
            new ColorHelper.ColorDescription("MediumPurple", "#FF9370DB"),
            new ColorHelper.ColorDescription("Thistle", "#FFD8BFD8"),
            new ColorHelper.ColorDescription("DarkMagenta", "#FF8B008B"),
            new ColorHelper.ColorDescription("DarkRed", "#FF8B0000"),
            new ColorHelper.ColorDescription("Indigo", "#FF4B0082"),
            new ColorHelper.ColorDescription("Crimson", "#FFDC143C")
        };

        public static readonly System.Windows.Media.Color DefaultColor = System.Windows.Media.Color.FromArgb(byte.MaxValue, 128, 128, 128);

        private struct ColorDescription
        {
            public ColorDescription(string name, string value)
            {
                this.Name = name;
                this.Value = value;
            }

            public static int Compare(ColorHelper.ColorDescription value1, ColorHelper.ColorDescription value2)
            {
                return value1.Name.CompareTo(value2.Name);
            }

            public string Name;

            public string Value;
        }
    }

    public static class DoubleExtensions
    {
        public static bool InRange(this double value, double min, double max)
        {
            return value >= min && value <= max;
        }

        public static double ToRange(this double value, double min, double max)
        {
            return Math.Min(Math.Max(value, min), max);
        }

        public static bool IsZero(this double value)
        {
            return Math.Abs(value) < 2.2204460492503131E-15;
        }

        public static double Round(this double value, bool toLower = false)
        {
            double num;
            if (toLower)
            {
                num = ((value > 0.0) ? Math.Floor(value) : Math.Ceiling(value));
            }
            else
            {
                num = ((value > 0.0) ? Math.Ceiling(value) : Math.Floor(value));
            }
            if (Math.Abs(num - value).AreClose(0.5))
            {
                return num;
            }
            return Math.Round(value);
        }

        public static bool AreClose(this double value1, double value2)
        {
            if (value1 == value2)
            {
                return true;
            }
            double num = (Math.Abs(value1) + Math.Abs(value2) + 10.0) * 2.2204460492503131E-16;
            double num2 = value1 - value2;
            return -num < num2 && num > num2;
        }

        public static bool AreClose(Size size1, Size size2)
        {
            return size1.Width.AreClose(size2.Width) && size1.Height.AreClose(size2.Height);
        }

        public static bool AreClose(Point point1, Point point2)
        {
            return point1.X.AreClose(point2.X) && point1.Y.AreClose(point2.Y);
        }

        public static bool GreaterThan(this double value1, double value2)
        {
            return value1 > value2 && !value1.AreClose(value2);
        }

        public static bool LessThan(this double value1, double value2)
        {
            return value1 < value2 && !value1.AreClose(value2);
        }

        public static bool LessThanOrClose(this double value1, double value2)
        {
            return value1 < value2 || value1.AreClose(value2);
        }

        public static bool GreaterThanOrClose(this double value1, double value2)
        {
            return value1 > value2 || value1.AreClose(value2);
        }
    }
}